! Configuration File for keepalived

global_defs {
   router_id {{ ansible_default_ipv4.address }}
   vrrp_mcast_group4 224.1.101.103
}

# 脚本监控kube-apiserver
vrrp_script check-kube-apiserver {
    script "/etc/keepalived/check-kube-apiserver.sh"
    weight -5
    interval 1
    fall 1
    rise 1
}

vrrp_instance VI_1 {
    state MASTER
    interface {{ ansible_default_ipv4.alias }}
    virtual_router_id 51
    priority {% if ansible_default_ipv4.address == groups.apiserver[0] %}100{% else %}90{% endif %}
    
    advert_int 1
    mcast_src_ip {{ ansible_default_ipv4.address }}
    nopreempt 	#非抢占
    authentication {
        auth_type PASS
        auth_pass hmOrGtxy2A
    }
    virtual_ipaddress {
        {{ keepalived_virtual_ipaddress }}
    }

    track_script {
       check-kube-apiserver 6433
    }
}
